#include "TRgbEx.h"

//#RRGGBB #RGB
void TRgbEx::ParseRGBL(const TDesC& aDes)
{
	TInt red = 0;
	TInt green = 0;
	TInt blue = 0;

	HBufC* pBuf = HBufC::NewL(aDes.Length());
	CleanupStack::PushL(pBuf);
	TPtr ptrBuf = pBuf->Des();
	ptrBuf.Copy(aDes);
	ptrBuf.Trim();

	if(pBuf->Length() <= 0)
		return;

	const TUint16* ptr = ptrBuf.Ptr();
	if(ptr[0] != '#')
		return;

	if(pBuf->Length() == 4)
	{
		TBuf<2> buf;
		TLex lex;

		buf.Append(&ptr[1],1);
		buf.Append(&ptr[1],1);
		lex = buf;
		lex.Val(red);
		SetRed(red);

		buf.Append(&ptr[2],1);
		buf.Append(&ptr[2],1);
		lex = buf;
		lex.Val(green);
		SetRed(green);

		buf.Append(&ptr[3],1);
		buf.Append(&ptr[3],1);
		lex = buf;
		lex.Val(blue);
		SetRed(blue);

	}
	else if(pBuf->Length() == 7)
	{
		TBuf<2> buf;
		TLex lex;

		buf.Append(ptr+1,2);
		lex = buf;
		lex.Val(red);
		SetRed(red);

		buf.Append(ptr+2,2);
		lex = buf;
		lex.Val(green);
		SetRed(green);

		buf.Append(ptr+3,2);
		lex = buf;
		lex.Val(blue);
		SetRed(blue);
	}

	CleanupStack::PopAndDestroy(1);
}